home *** CD-ROM | disk | FTP | other *** search
/ Network Support Library / RoseWare - Network Support Library.iso / btrieve / sql_dp.arj / XQLMDPMI.PAS < prev    next >
Pascal/Delphi Source File  |  1993-08-08  |  53KB  |  1,653 lines

  1. unit  XQLMDPMI;  { XQL-Manager DPMI Interface for Borland/Turbo Pascal 7.0 }
  2.                  { Dieter Dasberg                                          }
  3.  
  4.   interface 
  5.  
  6.     {$IfDef DPMI}
  7.       Uses DOS, WinAPI, SimRMI;
  8.     {$EndIf}
  9.  
  10.     {$IfDef Windows}
  11.       ERROR : Use the XQLM Windows interface from NOVELL
  12.     {$EndIf}
  13.  
  14.     {$IfDef MSDos}
  15.       ERROR : Use the XQLM MSDos interface from NOVELL
  16.     {$EndIf}
  17.  
  18.  
  19.  
  20.     const SQL_WORK_BUFFER_SIZE = 8192;  { bytes in MSDOS memory }
  21.  
  22.           STATUS_BUFFER_SIZE   =   30;  { bytes for the status buffer in }
  23.                                         { XQLStatus function             }
  24.  
  25.  
  26.     function  InitXQLMDPMI : integer; { Call this function before working   }
  27.                                       { with this interface! It first tests }
  28.                                       { if btrieve and xql/sql are availi-  }
  29.                                       { able and then allocates 3 workbuffer}
  30.                                       { in MSDOS memory. This makes the new }
  31.                                       { DPMI interface a little faster.     }
  32.  
  33.     procedure ExitXQLMDPMI;           { Call this function before leaving }
  34.                                       { your program to realease the xql- }
  35.                                       { DPMI workbuffer in MSDOS memory.  }
  36.  
  37.  
  38.     function  XQLLogin     (var UserId,
  39.                                 Pswd,
  40.                                 DataDic,
  41.                                 DataPath,
  42.                                 Machine;
  43.                                 ProcessId  : integer  ) : integer;
  44.  
  45.     function  XQLLogout                                 : integer;
  46.                                                       
  47.     function  XQLCursor    (var Cursor     : integer  ) : integer;
  48.  
  49.     function  XQLCompile   (    Cursor     : integer;
  50.                             var SLen       : integer;
  51.                             var Stmnt                 ) : integer;
  52.  
  53.     function  XQLFormat    (    Cursor,  
  54.                                 VPos,    
  55.                                 Len        : integer;
  56.                             var MaskBuf               ) : integer;
  57.  
  58.     function  XQLDescribe  (    Cursor,
  59.                                 VPos       : integer;
  60.                             var DType,
  61.                                 Size,
  62.                                 Dec,
  63.                                 DSize,
  64.                                 NLength    : integer;
  65.                             var Name                  ) : integer;
  66.  
  67.     function  XQLFetch     (    Cursor,
  68.                                 Op         : integer;
  69.                             var DLen       : integer;
  70.                             var Buf;
  71.                             var Sel        : longint;
  72.                                 ASCII,
  73.                                 Spaces     : integer  ) : integer;
  74.  
  75.     function  XQLSubst     (    Cursor,
  76.                                 SCount,
  77.                                 NameLen    : integer;
  78.                             var VarName;
  79.                                 TextLen    : integer;
  80.                             var VarText               ) : integer;
  81.  
  82.     function  XQLExec      (    Cursor     : integer  ) : integer;
  83.  
  84.     function  XQLFree      (    Cursor     : integer  ) : integer;
  85.  
  86.     function  XQLStatus    (    Cursor,  
  87.                                 SubFunc    : integer;
  88.                             var StatBuf               ) : integer;
  89.  
  90.     function  XQLStop                                   : integer;
  91.  
  92.     function  XQLVersion   (    VBuffer    : longint  ) : integer;
  93.  
  94.     function  XQLConvert   (    Option,
  95.                                 DType,
  96.                                 Size,
  97.                                 Dec,
  98.                                 DSize      : integer;
  99.                             var Value;
  100.                             var RetValue;
  101.                             var Mask;
  102.                                 Just       : integer  ) : integer;
  103.  
  104.     function  XQLValidate  (var Count      : integer;
  105.                             var FieldName;
  106.                                 BufLen     : integer;
  107.                             var Data                  ) : integer;
  108.  
  109.     function  XQLMask      (    Option,
  110.                                 DType,
  111.                                 Size,
  112.                                 Dec        : integer;
  113.                             var MLen       : integer;
  114.                             var Mask                  ) : integer;
  115.  
  116.     function  XQLSpUtility (    Cursor,
  117.                                 Option     : integer;
  118.                             var StmntCnt,  
  119.                                 StmntExec  : integer;
  120.                             var BufLen     : integer;
  121.                             var StatBuf               ) : integer;
  122.  
  123.   implementation
  124.  
  125.  
  126.     type  tSegOfs        = record                 { 32 bit address }
  127.                              Offset  : word;
  128.                              Segment : word;
  129.                            end;
  130.     
  131.           tDosAlloc      = record case boolean of
  132.                              TRUE  : (Addresses : LongInt);
  133.                              FALSE : (Selector  : word;
  134.                                       Segment   : word;  );
  135.                            end;
  136.  
  137.           tXQLMID        = array[0..3] of char;
  138.  
  139.           tXQLMStruc     = record                 { structure passed to XQLM }
  140.                              XQLMID        : tXQLMID;
  141.                              Fcn           : integer;
  142.                              CursorID      : integer;
  143.                              Stat          : integer;
  144.                              SessionID     : integer;
  145.                            end;
  146.  
  147.  
  148.           tBtrieve       = record
  149.                                       Dumy1            : integer;
  150.                                       BtrOp            : integer;
  151.                                       Dumy2            : integer;
  152.                                       Dumy3            : integer;
  153.                                       Dumy4            : integer;
  154.                                       BtrStat       : tSegOfs;
  155.                            end;
  156.  
  157.           tBtrieveStruc  = record
  158.                              XQLMStruc     : tXQLMStruc;
  159.                              BtrieveRec    : tBtrieve;
  160.                            end;
  161.  
  162.  
  163.           tLogin         = record
  164.                              UserID        : tSegOfs;
  165.                              Pswd          : tSegOfs;
  166.                              DataDic       : tSegOfs;
  167.                              DataPath      : tSegOfs;
  168.                              Machine       : tSegOfs;
  169.                              ProcessId     : integer;
  170.                            end;
  171.  
  172.           tLoginStruc    = record
  173.                              XQLMStruc     : tXQLMStruc;
  174.                              LoginRec      : tLogin;
  175.                            end;
  176.  
  177.  
  178.           tCompile       = record
  179.                              Len           : integer;
  180.                              Statement     : tSegOfs;
  181.                            end;                 
  182.  
  183.           tCompileStruc  = record
  184.                              XQLMStruc     : tXQLMStruc;
  185.                              CompileRec    : tCompile;
  186.                            end;
  187.  
  188.  
  189.           tFormat        = record
  190.                              Position      : integer;
  191.                              MaskLen       : integer;
  192.                              Mask          : tSegOfs;
  193.                            end;                 
  194.  
  195.           tFormatStruc   = record
  196.                              XQLMStruc     : tXQLMStruc;
  197.                              FormatRec     : tFormat;
  198.                            end;
  199.  
  200.  
  201.           tFetch         = record
  202.                              Operation     : integer;
  203.                              DataLen       : integer;
  204.                              DataBuf       : tSegOfs;
  205.                              Select        : longint;
  206.                              ASCIIFlag     : integer;
  207.                              Spacing       : integer;
  208.                            end;                 
  209.  
  210.           tFetchStruc    = record
  211.                              XQLMStruc     : tXQLMStruc;
  212.                              FetchRec      : tFetch;
  213.                            end;
  214.  
  215.  
  216.           tDescr         = record
  217.                              Position      : integer;
  218.                              DataType      : integer;
  219.                              DataSize      : integer;
  220.                              DecCount      : integer;
  221.                              DispSize      : integer;
  222.                              NameLength    : integer;
  223.                              NameBuf       : tSegOfs;
  224.                            end;                 
  225.  
  226.           tDescrStruc    = record
  227.                              XQLMStruc     : tXQLMStruc;
  228.                              DescrRec      : tDescr;
  229.                            end;
  230.  
  231.  
  232.           tSubst         = record      
  233.                              Count         : integer;
  234.                              NLen          : integer;
  235.                              VName         : tSegOfs;
  236.                              TLen          : integer;
  237.                              VText         : tSegOfs;
  238.                            end;                  
  239.  
  240.           tSubstStruc    = record      
  241.                              XQLMStruc     : tXQLMStruc;
  242.                              SubstRec      : tSubst;
  243.                            end;        
  244.  
  245.  
  246.           tStatus        = record      
  247.                              SubFunctn     : integer;
  248.                              Buf           : tSegOfs;
  249.                            end;                  
  250.  
  251.           tStatusStruc   = record      
  252.                              XQLMStruc     : tXQLMStruc;
  253.                              StatusRec     : tStatus;
  254.                            end;        
  255.  
  256.  
  257.           tVersion       = record
  258.                              Buffer        : tSegOfs;
  259.                            end;                
  260.  
  261.           tVersionStruc  = record
  262.                              XQLMStruc     : tXQLMStruc;
  263.                              VersionRec    : tVersion;
  264.                            end;
  265.  
  266.  
  267.           tConvert       = record
  268.                              ConvFcn       : integer;
  269.                              ConvType      : integer;
  270.                              ConvSize      : integer;
  271.                              ConvDec       : integer;
  272.                              ConvDSize     : integer;
  273.                              ConvVal       : tSegOfs;
  274.                              ConvRet       : tSegOfs;
  275.                              ConvMask      : tSegOfs;
  276.                              ConvJust      : integer;
  277.                            end;                 
  278.  
  279.           tConvertStruc  = record
  280.                              XQLMStruc     : tXQLMStruc;
  281.                              ConvertRec    : tConvert;
  282.                            end;
  283.  
  284.  
  285.           tValidate       = record
  286.                              ValCount      : integer;
  287.                              ValField      : tSegOfs;
  288.                              ValBufLen     : integer;
  289.                              ValData       : tSegOfs;
  290.                            end;                
  291.  
  292.           tValidateStruc = record
  293.                              XQLMStruc     : tXQLMStruc;
  294.                              ValidateRec   : tValidate;
  295.                            end;
  296.  
  297.  
  298.           tMask          = record       
  299.                              MaskOption    : integer;
  300.                              MaskType      : integer;
  301.                              MaskSize      : integer;
  302.                              MaskDec       : integer;
  303.                              MaskLen       : integer;
  304.                              MaskVal       : tSegOfs;
  305.                            end;                 
  306.  
  307.           tMaskStruc     = record       
  308.                              XQLMStruc     : tXQLMStruc;
  309.                              MaskRec       : tMask;
  310.                            end;         
  311.  
  312.  
  313.           tSpUtil        = record
  314.                              UtilOption    : integer;
  315.                              UtilStmntCnt  : integer;
  316.                              UtilStmntExec : integer;
  317.                              UtilBufLen    : integer;
  318.                              UtilStatBuf   : tSegOfs;
  319.                            end;              
  320.  
  321.           tSpUtilStruc   = record
  322.                              XQLMStruc     : tXQLMStruc;
  323.                              SpUtilRec     : tSpUtil;
  324.                            end;
  325.  
  326.  
  327.           pXQLMArray     = ^tXQLMArray;
  328.           tXQLMArray     = array[0..SQL_WORK_BUFFER_SIZE] of char;
  329.  
  330.           tXQLMBuff      = record
  331.                              DPMIAddr : tDosAlloc;
  332.                              Buffer   : pXQLMArray;
  333.                            end;
  334.  
  335.           pString        = ^string;
  336.           pInteger       = ^integer;
  337.  
  338.  
  339.     const XQLMBUFFS      = 3;
  340.  
  341.           { XQL func's,   "*"  means that it is not tested yet! }
  342.           FCN_INV        =    -1; { investigate           }
  343.           FCN_LOG_IN     =     0; { login                 } 
  344.           FCN_LOG_OUT    =     1; { logout                } 
  345.           FCN_CURSOR     =     2; { get cursor            } 
  346.           FCN_COMPILE    =     3; { compile statement     }
  347.           FCN_FORMAT     =     4; { format data           } { * }
  348.           FCN_FETCH      =     5; { fetch data            } 
  349.           FCN_DESCRIBE   =     6; { describe statement    } 
  350.           FCN_SUBST      =     7; { substitute variables  } 
  351.           FCN_EXEC       =     8; { execute statement     } 
  352.           FCN_FREE       =     9; { free cursor           } 
  353.           FCN_STAT       =    10; { status information    } { * }
  354.           FCN_STOP       =    11; { stop xqlm NOT IN DPMI }      
  355.           FCN_VERS       =    12; { version of xqlm       } { * }
  356.           FCN_CONV       =    13; { convert variables     } { * }
  357.           FCN_VAL        =    14; { validate              } { * }
  358.           FCN_MASK       =    15; { mask operation        } { * }
  359.           FCN_SPUTIL     =    16; { special util          } { * }
  360.  
  361.           FCN_BTRIEVE    =    17; { not XQLM, just needed to have an index   }
  362.           FCN_XQLM_STRUC =     2; { all func's which uses only the XQLMStruc }
  363.                                   { use the same buffer (pXQLMStruc) as the  }
  364.                                   { login-func.                              }
  365.  
  366.  
  367.     var   SQLCode    : integer;
  368.           Regs       : TRealModeRecord;
  369.           XQLMBuffer : array[1..XQLMBUFFS] of tXQLMBuff;
  370.           XQLMFuncs  : array[FCN_LOG_IN..FCN_BTRIEVE] of tDosAlloc;
  371.  
  372.           pXQLMStruc : ^tXQLMStruc;
  373.  
  374.           pBtrieve   : ^tBtrieveStruc;
  375.           pBtrStat   : pInteger;
  376.           BStat      : integer;
  377.  
  378.           pLogin     : ^tLoginStruc;
  379.           pUserID    : pString;
  380.           pPswd      : pString;
  381.           pDataDic   : pString;
  382.           pDataPath  : pString;
  383.           pMachine   : pString;
  384.  
  385.           pCompile   : ^tCompileStruc;
  386.           pFormat    : ^tFormatStruc;
  387.           pFetch     : ^tFetchStruc;
  388.           pDescr     : ^tDescrStruc;
  389.           pSubst     : ^tSubstStruc;
  390.           pStatus    : ^tStatusStruc;
  391.           pVersion   : ^tVersionStruc;
  392.           pConvert   : ^tConvertStruc;
  393.           pValidate  : ^tValidateStruc;
  394.           pMask      : ^tMaskStruc;
  395.           pSpUtil    : ^tSpUtilStruc;
  396.  
  397.  
  398.     const XQLM_ID    : tXQLMID = ('X','Q','L','M');
  399.  
  400.           XQLMLoaded : boolean = FALSE;         
  401.           SessID     : integer =    -1; { session identifier for XQL }
  402.  
  403.           DPMI_INTERFACE_FAIL  = 22222; { any value but no Btrieve/XQL error }
  404.           BTRV_NOT_LOADED      =    20; 
  405.           XQLM_NOT_LOADED      =   200; 
  406.  
  407.           BTR_INT              =   $7B; { Btrieve interrupt }
  408.           DOS_INT              =   $21; { DOS interrupt }
  409.           DPMI_INT             =   $31; { DPMI real mode interrupt }
  410.  
  411.           BTR_OFFSET           = $0033;
  412.  
  413.           FCN_RES_INV_XQLM     =   503;
  414.  
  415.  
  416.     function XQLLogin(var UserId,
  417.                           Pswd,
  418.                           DataDic,
  419.                           DataPath,
  420.                           Machine;
  421.                           ProcessId : integer ) : integer;
  422.       begin
  423.         SQLCode := DPMI_INTERFACE_FAIL;
  424.  
  425.         if XQLMLoaded then
  426.           begin
  427.             pLogin^.LoginRec.ProcessID := ProcessID;
  428.     
  429.             with pLogin^.XQLMStruc do
  430.               begin
  431.                 XQLMID    := XQLM_ID;
  432.                 Fcn       := FCN_LOG_IN;
  433.                 CursorId  := 0;
  434.                 SessionID := SessID;
  435.               end;
  436.     
  437.             Move(UserId,   pUserID^,   SizeOf(string));
  438.             Move(Pswd,     pPswd^,     SizeOf(string));
  439.             Move(DataDic,  pDataDic^,  SizeOf(string));
  440.             Move(DataPath, pDataPath^, SizeOf(string));
  441.             Move(Machine,  pMachine^,  SizeOf(string));
  442.  
  443.             Regs    := DefaultRMR;
  444.             Regs.DS := XQLMFuncs[FCN_LOG_IN].Segment;
  445.     
  446.             if SimRMI.SimRealModeInt(BTR_INT,@Regs) then
  447.               SQLCode := pLogin^.XQLMStruc.Stat;
  448.     
  449.             if (SQLCode=0) then
  450.               begin
  451.                 SessID := pLogin^.XQLMStruc.SessionId;
  452.                 XQLMLoaded := TRUE;         
  453.               end;
  454.           end
  455.         else
  456.           SQLCode := XQLM_NOT_LOADED;
  457.  
  458.         XQLLogin := SQLCode;
  459.       end;
  460.  
  461.  
  462.     function XQLLogout : integer;
  463.       begin
  464.         SQLCode := DPMI_INTERFACE_FAIL;
  465.  
  466.         if XQLMLoaded then
  467.           begin
  468.            FillChar(pXQLMStruc^, SizeOf(tXQLMStruc), #0);
  469.            with pXQLMStruc^ do
  470.              begin
  471.                XQLMID    := XQLM_ID;
  472.                Fcn       := FCN_LOG_OUT;
  473.                SessionID := SessID;
  474.              end;
  475.     
  476.            Regs    := DefaultRMR;
  477.            Regs.DS := XQLMFuncs[FCN_XQLM_STRUC].Segment;
  478.     
  479.            if SimRMI.SimRealModeInt(BTR_INT,@Regs) then
  480.              SQLCode := pXQLMStruc^.Stat;
  481.           end
  482.         else
  483.           SQLCode := XQLM_NOT_LOADED;
  484.  
  485.         XQLLogout := SQLCode;
  486.       end;
  487.  
  488.  
  489.     function XQLCursor(var Cursor : integer) : integer;
  490.       begin
  491.         SQLCode := DPMI_INTERFACE_FAIL;
  492.  
  493.         if XQLMLoaded then
  494.           begin
  495.            FillChar(pXQLMStruc^, SizeOf(tXQLMStruc), #0);
  496.            with pXQLMStruc^ do
  497.              begin
  498.                XQLMID    := XQLM_ID;
  499.                Fcn       := FCN_CURSOR;
  500.                CursorId  := -1;
  501.                SessionID := SessID;
  502.              end;
  503.     
  504.            Regs    := DefaultRMR;
  505.            Regs.DS := XQLMFuncs[FCN_XQLM_STRUC].Segment;
  506.     
  507.            if SimRMI.SimRealModeInt(BTR_INT,@Regs) then
  508.              begin
  509.                SQLCode := pXQLMStruc^.Stat;
  510.  
  511.                if (SQLCode=0) then
  512.                  Cursor := pXQLMStruc^.CursorId;
  513.              end;
  514.           end
  515.         else
  516.           SQLCode := XQLM_NOT_LOADED;
  517.  
  518.         XQLCursor := SQLCode;
  519.       end;
  520.  
  521.  
  522.     function XQLCompile(    Cursor : integer;
  523.                         var SLen   : integer;
  524.                         var Stmnt             ) : integer;
  525.       begin
  526.         SQLCode := DPMI_INTERFACE_FAIL;
  527.  
  528.         if XQLMLoaded then
  529.           begin
  530.             FillChar(pCompile^, SizeOf(tCompileStruc), #0);
  531.  
  532.             with pCompile^.XQLMStruc do
  533.               begin
  534.                 XQLMID    := XQLM_ID;
  535.                 Fcn       := FCN_COMPILE;
  536.                 CursorID  := Cursor;
  537.                 SessionID := SessID;
  538.               end;
  539.  
  540.             with pCompile^.CompileRec do
  541.               begin
  542.                 Statement.Offset  := 0;
  543.                 Statement.Segment := XQLMBuffer[1].DPMIAddr.Segment;
  544.                 Len               := SLen;
  545.  
  546.                 FillChar(XQLMBuffer[1].Buffer^, SQL_WORK_BUFFER_SIZE, #0);
  547.                 Move(Stmnt, XQLMBuffer[1].Buffer^, SLen);
  548.               end;
  549.  
  550.             Regs    := DefaultRMR;
  551.             Regs.DS := XQLMFuncs[FCN_COMPILE].Segment;
  552.     
  553.             if SimRMI.SimRealModeInt(BTR_INT,@Regs) then
  554.               SQLCode := pCompile^.XQLMStruc.Stat;
  555.  
  556.             if (SQLCode<=0) then
  557.               SLen := pCompile^.CompileRec.Len;
  558.           end
  559.         else
  560.           SQLCode := XQLM_NOT_LOADED;
  561.  
  562.         XQLCompile := SQLCode;
  563.       end;
  564.  
  565.  
  566.  
  567.     function XQLFormat(    Cursor,
  568.                            VPos,
  569.                            Len     : integer;
  570.                        var MaskBuf            ) : integer;
  571.       begin
  572.         SQLCode := DPMI_INTERFACE_FAIL;
  573.  
  574.         if XQLMLoaded then
  575.           begin
  576.             FillChar(pFormat^, SizeOf(tFormatStruc), #0);
  577.  
  578.             with pFormat^.XQLMStruc do
  579.               begin
  580.                 XQLMID    := XQLM_ID;
  581.                 Fcn       := FCN_FORMAT;
  582.                 CursorID  := Cursor;
  583.                 SessionID := SessID;
  584.               end;
  585.  
  586.             with pFormat^.FormatRec do
  587.               begin
  588.                 Position     := VPos;
  589.                 Mask.Offset  := 0;
  590.                 Mask.Segment := XQLMBuffer[1].DPMIAddr.Segment;
  591.                 MaskLen      := Len;
  592.  
  593.                 FillChar(XQLMBuffer[1].Buffer^, SQL_WORK_BUFFER_SIZE, #0);
  594.                 Move(MaskBuf, XQLMBuffer[1].Buffer^, Len);
  595.               end;
  596.  
  597.             Regs    := DefaultRMR;
  598.             Regs.DS := XQLMFuncs[FCN_FORMAT].Segment;
  599.     
  600.             if SimRMI.SimRealModeInt(BTR_INT,@Regs) then
  601.               SQLCode := pFormat^.XQLMStruc.Stat;
  602.           end
  603.         else
  604.           SQLCode := XQLM_NOT_LOADED;
  605.  
  606.         XQLFormat := SQLCode;
  607.       end;
  608.  
  609.  
  610.  
  611.     function XQLFetch(    Cursor,
  612.                          Op      : integer;
  613.                      var DLen    : integer;
  614.                      var Buf;
  615.                      var Sel     : longint;
  616.                          ASCII,
  617.                          Spaces  : integer  ) : integer;
  618.       begin
  619.         SQLCode := DPMI_INTERFACE_FAIL;
  620.  
  621.         if XQLMLoaded then
  622.           begin
  623.             FillChar(pFetch^, SizeOf(tFetchStruc), #0);
  624.  
  625.             with pFetch^.XQLMStruc do
  626.               begin
  627.                 XQLMID    := XQLM_ID;
  628.                 Fcn       := FCN_FETCH;
  629.                 CursorID  := Cursor;
  630.                 SessionID := SessID;
  631.               end;
  632.  
  633.             with pFetch^.FetchRec do
  634.               begin
  635.                 Operation := OP;
  636.                 DataLen   := DLen;
  637.                 Select    := Sel;
  638.                 ASCIIFlag := ASCII;
  639.                 Spacing   := Spaces;
  640.  
  641.                 DataBuf.Offset  := 0;
  642.                 DataBuf.Segment := XQLMBuffer[1].DPMIAddr.Segment;
  643.                 FillChar(XQLMBuffer[1].Buffer^, SQL_WORK_BUFFER_SIZE, #32);
  644.               end;
  645.  
  646.             Regs    := DefaultRMR;
  647.             Regs.DS := XQLMFuncs[FCN_FETCH].Segment;
  648.     
  649.             if SimRMI.SimRealModeInt(BTR_INT,@Regs) then
  650.               SQLCode := pFetch^.XQLMStruc.Stat;
  651.  
  652.             if (SQLCode<=0) then
  653.               begin
  654.                 DLen := pFetch^.FetchRec.DataLen;
  655.                 Sel  := pFetch^.FetchRec.Select;
  656.                 Move(XQLMBuffer[1].Buffer^, Buf, DLen);
  657.               end;
  658.           end
  659.         else
  660.           SQLCode := XQLM_NOT_LOADED;
  661.  
  662.         XQLFetch := SQLCode;
  663.       end;
  664.  
  665.  
  666.  
  667.     function XQLDescribe(    Cursor,
  668.                              VPos    : integer;
  669.                          var DType,
  670.                              Size,
  671.                              Dec,
  672.                              DSize,
  673.                              NLength : integer;
  674.                          var Name               ) : integer;
  675.       begin
  676.         SQLCode := DPMI_INTERFACE_FAIL;
  677.  
  678.         if XQLMLoaded then
  679.           begin
  680.             FillChar(pDescr^, SizeOf(tDescrStruc), #0);
  681.  
  682.             with pDescr^.XQLMStruc do
  683.               begin
  684.                 XQLMID    := XQLM_ID;
  685.                 Fcn       := FCN_DESCRIBE;
  686.                 CursorID  := Cursor;
  687.                 SessionID := SessID;
  688.               end;
  689.     
  690.             with pDescr^.DescrRec do
  691.               begin
  692.                 Position    := VPos;
  693.                 NameLength  := NLength;
  694.  
  695.                 NameBuf.Offset  := 0;
  696.                 NameBuf.Segment := XQLMBuffer[1].DPMIAddr.Segment;
  697.  
  698.                 FillChar(XQLMBuffer[1].Buffer^, SQL_WORK_BUFFER_SIZE, #0);
  699.                 Move(Name, XQLMBuffer[1].Buffer^, NLength);
  700.               end;
  701.     
  702.             Regs    := DefaultRMR;
  703.             Regs.DS := XQLMFuncs[FCN_DESCRIBE].Segment;
  704.         
  705.             if SimRMI.SimRealModeInt(BTR_INT,@Regs) then
  706.               SQLCode := pDescr^.XQLMStruc.Stat;
  707.     
  708.             if (SQLCode<=0) then
  709.               begin
  710.                 DType   := pDescr^.DescrRec.DataType;
  711.                 Size    := pDescr^.DescrRec.DataSize;
  712.                 Dec     := pDescr^.DescrRec.DecCount;
  713.                 DSize   := pDescr^.DescrRec.DispSize;
  714.                 NLength := pDescr^.DescrRec.NameLength;
  715.  
  716.                 Move(XQLMBuffer[1].Buffer^, Name, NLength);
  717.               end;
  718.           end
  719.         else
  720.           SQLCode := XQLM_NOT_LOADED;
  721.  
  722.         XQLDescribe := SQLCode;
  723.       end;
  724.  
  725.  
  726.  
  727.     function XQLSubst(    Cursor,
  728.                           SCount,
  729.                           NameLen  : integer;
  730.                       var VarName;
  731.                           TextLen  : integer;
  732.                       var VarText             ) : integer;
  733.       begin
  734.         SQLCode := DPMI_INTERFACE_FAIL;
  735.  
  736.         if XQLMLoaded then
  737.           begin
  738.             FillChar(pSubst^, SizeOf(tSubstStruc), #0);
  739.  
  740.             with pSubst^.XQLMStruc do
  741.               begin
  742.                 XQLMID    := XQLM_ID;
  743.                 Fcn       := FCN_SUBST;
  744.                 CursorID  := Cursor;
  745.                 SessionID := SessID;
  746.               end;
  747.  
  748.             with pSubst^.SubstRec do
  749.               begin
  750.                 VName.Offset  := 0;
  751.                 VName.Segment := XQLMBuffer[1].DPMIAddr.Segment;
  752.                 NLen          := NameLen;
  753.  
  754.                 VText.Offset  := 0;
  755.                 VText.Segment := XQLMBuffer[2].DPMIAddr.Segment;
  756.                 TLen          := TextLen;
  757.  
  758.                 FillChar(XQLMBuffer[1].Buffer^, SQL_WORK_BUFFER_SIZE, #0);
  759.                 Move(VarName, XQLMBuffer[1].Buffer^, NameLen);
  760.  
  761.                 FillChar(XQLMBuffer[2].Buffer^, SQL_WORK_BUFFER_SIZE, #0);
  762.                 Move(VarText, XQLMBuffer[2].Buffer^, TextLen);
  763.  
  764.                 Count := SCount;
  765.               end;
  766.  
  767.             Regs    := DefaultRMR;
  768.             Regs.DS := XQLMFuncs[FCN_SUBST].Segment;
  769.     
  770.             if SimRMI.SimRealModeInt(BTR_INT,@Regs) then
  771.               SQLCode := pSubst^.XQLMStruc.Stat;
  772.           end
  773.         else
  774.           SQLCode := XQLM_NOT_LOADED;
  775.  
  776.         XQLSubst := SQLCode;
  777.       end;
  778.  
  779.  
  780.  
  781.     function XQLExec(Cursor:integer):integer;
  782.       begin
  783.         SQLCode := DPMI_INTERFACE_FAIL;
  784.  
  785.         if XQLMLoaded then
  786.           begin
  787.             FillChar(pXQLMStruc^, SizeOf(tXQLMStruc), #0);
  788.             with pXQLMStruc^ do
  789.               begin
  790.                 XQLMID    := XQLM_ID;
  791.                 Fcn       := FCN_EXEC;
  792.                 CursorID  := Cursor;
  793.                 SessionID := SessID;
  794.               end;
  795.     
  796.             Regs    := DefaultRMR;
  797.             Regs.DS := XQLMFuncs[FCN_XQLM_STRUC].Segment;
  798.     
  799.             if SimRMI.SimRealModeInt(BTR_INT,@Regs) then
  800.               SQLCode := pXQLMStruc^.Stat;
  801.           end
  802.         else
  803.           SQLCode := XQLM_NOT_LOADED;
  804.  
  805.         XQLExec := SQLCode;
  806.       end;
  807.   
  808.   
  809.     function XQLFree(Cursor:integer):integer;
  810.       begin
  811.         SQLCode := DPMI_INTERFACE_FAIL;
  812.  
  813.         if XQLMLoaded then
  814.           begin
  815.             FillChar(pXQLMStruc^, SizeOf(tXQLMStruc), #0);
  816.             with pXQLMStruc^ do
  817.               begin
  818.                 XQLMID    := XQLM_ID;
  819.                 Fcn       := FCN_FREE;
  820.                 CursorID  := Cursor;
  821.                 SessionID := SessID;
  822.               end;
  823.  
  824.             Regs    := DefaultRMR;
  825.             Regs.DS := XQLMFuncs[FCN_XQLM_STRUC].Segment;
  826.  
  827.             if SimRMI.SimRealModeInt(BTR_INT,@Regs) then
  828.               SQLCode := pXQLMStruc^.Stat;
  829.           end
  830.         else
  831.           SQLCode := XQLM_NOT_LOADED;
  832.  
  833.         XQLFree := SQLCode;
  834.       end;
  835.   
  836.   
  837.     function XQLStatus(    Cursor,
  838.                            SubFunc : integer;
  839.                        var StatBuf            ) : integer;
  840.       begin
  841.         SQLCode := DPMI_INTERFACE_FAIL;
  842.  
  843.         if XQLMLoaded then
  844.           begin
  845.             FillChar(pStatus^, SizeOf(tStatusStruc), #0);
  846.  
  847.             with pStatus^.XQLMStruc do
  848.               begin
  849.                 XQLMID    := XQLM_ID;
  850.                 Fcn       := FCN_STAT;
  851.                 CursorID  := Cursor;
  852.                 SessionID := SessID;
  853.               end;
  854.  
  855.             with pStatus^.StatusRec do
  856.               begin
  857.                 SubFunctn   := SubFunc;
  858.  
  859.                 Buf.Offset  := 0;
  860.                 Buf.Segment := XQLMBuffer[1].DPMIAddr.Segment;
  861.  
  862.                 FillChar(XQLMBuffer[1].Buffer^, SQL_WORK_BUFFER_SIZE, #32);
  863.               end;
  864.  
  865.             Regs    := DefaultRMR;
  866.             Regs.DS := XQLMFuncs[FCN_STAT].Segment;
  867.     
  868.             if SimRMI.SimRealModeInt(BTR_INT,@Regs) then
  869.               SQLCode := pStatus^.XQLMStruc.Stat;
  870.  
  871.             if (SQLCode<=0) then
  872.               Move(XQLMBuffer[1].Buffer^, StatBuf, STATUS_BUFFER_SIZE);
  873.           end
  874.         else
  875.           SQLCode := XQLM_NOT_LOADED;
  876.  
  877.         XQLStatus := SQLCode;
  878.       end;
  879.  
  880.  
  881.  
  882.     function XQLStop : integer;
  883.       begin
  884.         { This func is not allowed in DPMI }
  885.         XQLStop := DPMI_INTERFACE_FAIL;
  886.       end;
  887.  
  888.  
  889.     function XQLVersion(VBuffer : longint) : integer;
  890.       begin
  891.         SQLCode := DPMI_INTERFACE_FAIL;
  892.  
  893.         if XQLMLoaded then
  894.           begin
  895.             FillChar(pVersion^, SizeOf(tVersionStruc), #0);
  896.  
  897.             with pVersion^.XQLMStruc do
  898.               begin
  899.                 XQLMID := XQLM_ID;
  900.                 Fcn    := FCN_VERS;
  901.               end;
  902.  
  903.             with pVersion^.VersionRec do
  904.               begin
  905.                 Buffer.Offset  := 0;
  906.                 Buffer.Segment := XQLMBuffer[1].DPMIAddr.Segment;
  907.  
  908.                 FillChar(XQLMBuffer[1].Buffer^, SQL_WORK_BUFFER_SIZE, #32);
  909.               end;
  910.  
  911.             Regs    := DefaultRMR;
  912.             Regs.DS := XQLMFuncs[FCN_VERS].Segment;
  913.     
  914.             if SimRMI.SimRealModeInt(BTR_INT,@Regs) then
  915.               SQLCode := pVersion^.XQLMStruc.Stat;
  916.  
  917.             if (SQLCode<=0) then
  918.               Move(XQLMBuffer[1].Buffer^, VBuffer, SizeOf(LongInt));
  919.           end
  920.         else
  921.           SQLCode := XQLM_NOT_LOADED;
  922.  
  923.         XQLVersion := SQLCode;
  924.       end;
  925.  
  926.  
  927.  
  928.     function  XQLConvert (    Option,
  929.                               DType,
  930.                               Size,
  931.                               Dec,
  932.                               DSize     : integer;
  933.                           var Value;
  934.                           var RetValue;
  935.                           var Mask;
  936.                               Just      : integer  ) : integer;
  937.       var i : integer;
  938.       begin
  939.         SQLCode := DPMI_INTERFACE_FAIL;
  940.  
  941.         if XQLMLoaded then
  942.           begin
  943.             FillChar(pConvert^, SizeOf(tConvertStruc), #0);
  944.  
  945.             with pConvert^.XQLMStruc do
  946.               begin
  947.                 XQLMID := XQLM_ID;
  948.                 Fcn    := FCN_CONV;
  949.               end;
  950.  
  951.             with pConvert^.ConvertRec do
  952.               begin
  953.                 ConvFcn          := Option;
  954.                 ConvType         := DType;
  955.                 ConvSize         := Size;
  956.                 ConvDec          := Dec;
  957.                 ConvDSize        := DSize;
  958.                 ConvJust         := Just;
  959.                 ConvVal.Offset   := 0; 
  960.                 ConvVal.Segment  := XQLMBuffer[1].DPMIAddr.Segment; 
  961.                 ConvRet.Offset   := 0; 
  962.                 ConvRet.Segment  := XQLMBuffer[2].DPMIAddr.Segment; 
  963.                 ConvMask.Offset  := 0;
  964.                 ConvMask.Segment := XQLMBuffer[3].DPMIAddr.Segment;
  965.  
  966.                 Move(Value, XQLMBuffer[1].Buffer^, pred(SQL_WORK_BUFFER_SIZE));
  967.  
  968.                 FillChar(XQLMBuffer[2].Buffer^, SQL_WORK_BUFFER_SIZE, #32);
  969.  
  970.                 Move(Mask,  XQLMBuffer[3].Buffer^, pred(SQL_WORK_BUFFER_SIZE));
  971.               end;
  972.  
  973.             Regs    := DefaultRMR;
  974.             Regs.DS := XQLMFuncs[FCN_CONV].Segment;
  975.     
  976.             if SimRMI.SimRealModeInt(BTR_INT,@Regs) then
  977.               SQLCode := pConvert^.XQLMStruc.Stat;
  978.  
  979.             if (SQLCode<=0) then
  980.               begin
  981.                 i := 0;
  982.                 while (XQLMBuffer[2].Buffer^[i]<>#0) and (i<SQL_WORK_BUFFER_SIZE) do 
  983.                   inc(i);
  984.  
  985.                 Move(XQLMBuffer[2].Buffer^,RetValue,i);
  986.               end;
  987.           end
  988.         else
  989.           SQLCode := XQLM_NOT_LOADED;
  990.  
  991.         XQLConvert := SQLCode;
  992.       end;
  993.  
  994.  
  995.  
  996.     function XQLValidate(var Count        : integer;
  997.                          var FieldName;
  998.                              BufLen       : integer;
  999.                          var Data                    ) : integer;
  1000.       begin
  1001.         SQLCode := DPMI_INTERFACE_FAIL;
  1002.  
  1003.         if XQLMLoaded then
  1004.           begin
  1005.             FillChar(pValidate^, SizeOf(tValidateStruc), #0);
  1006.  
  1007.             with pValidate^.XQLMStruc do
  1008.               begin
  1009.                 XQLMID := XQLM_ID;
  1010.                 Fcn    := FCN_VAL;
  1011.               end;
  1012.  
  1013.             with pValidate^.ValidateRec do
  1014.               begin
  1015.                 ValCount         := Count;
  1016.                 ValBufLen        := BufLen;
  1017.  
  1018.                 ValField.Offset  := 0;
  1019.                 ValField.Segment := XQLMBuffer[1].DPMIAddr.Segment;
  1020.  
  1021.                 ValData.Offset   := 0;
  1022.                 ValData.Segment  := XQLMBuffer[2].DPMIAddr.Segment;
  1023.  
  1024.                 Move(FieldName, XQLMBuffer[1].Buffer^, pred(SQL_WORK_BUFFER_SIZE));
  1025.  
  1026.                 FillChar(XQLMBuffer[2].Buffer^, SQL_WORK_BUFFER_SIZE, #0);
  1027.                 Move(Data, XQLMBuffer[2].Buffer^, BufLen);
  1028.               end;
  1029.  
  1030.             Regs    := DefaultRMR;
  1031.             Regs.DS := XQLMFuncs[FCN_VAL].Segment;
  1032.     
  1033.             if SimRMI.SimRealModeInt(BTR_INT,@Regs) then
  1034.               SQLCode := pValidate^.XQLMStruc.Stat;
  1035.  
  1036.             if (SQLCode<=0) then
  1037.               Count := pValidate^.ValidateRec.ValCount;
  1038.           end
  1039.         else
  1040.           SQLCode := XQLM_NOT_LOADED;
  1041.  
  1042.         XQLValidate := SQLCode;
  1043.       end;
  1044.  
  1045.  
  1046.  
  1047.     function  XQLMask(    Option,
  1048.                           DType,
  1049.                           Size,
  1050.                           Dec        : integer;
  1051.                       var MLen       : integer;
  1052.                       var Mask                  ) : integer;
  1053.       begin
  1054.         SQLCode := DPMI_INTERFACE_FAIL;
  1055.  
  1056.         if XQLMLoaded then
  1057.           begin
  1058.             FillChar(pMask^, SizeOf(tMaskStruc), #0);
  1059.  
  1060.             with pMask^.XQLMStruc do
  1061.               begin
  1062.                 XQLMID := XQLM_ID;
  1063.                 Fcn    := FCN_MASK;
  1064.               end;
  1065.  
  1066.             with pMask^.MaskRec do
  1067.               begin
  1068.                 MaskOption      := Option;
  1069.                 MaskType        := DType;
  1070.                 MaskSize        := Size;
  1071.                 MaskDec         := Dec;
  1072.                 MaskLen         := MLen;
  1073.  
  1074.                 MaskVal.Offset  := 0;
  1075.                 MaskVal.Segment := XQLMBuffer[1].DPMIAddr.Segment;
  1076.  
  1077.                 FillChar(XQLMBuffer[1].Buffer^, SQL_WORK_BUFFER_SIZE, #0);
  1078.                 Move(Mask, XQLMBuffer[1].Buffer^, MLen);
  1079.               end;
  1080.  
  1081.             Regs    := DefaultRMR;
  1082.             Regs.DS := XQLMFuncs[FCN_MASK].Segment;
  1083.     
  1084.             if SimRMI.SimRealModeInt(BTR_INT,@Regs) then
  1085.               SQLCode := pMask^.XQLMStruc.Stat;
  1086.  
  1087.             if (SQLCode<=0) then
  1088.               begin
  1089.                 MLen := pMask^.MaskRec.MaskLen;
  1090.                 Move(XQLMBuffer[1].Buffer^, Mask, MLen);
  1091.               end;
  1092.           end
  1093.         else
  1094.           SQLCode := XQLM_NOT_LOADED;
  1095.  
  1096.         XQLMask := SQLCode;
  1097.       end;
  1098.  
  1099.  
  1100.     function XQLSpUtility(    Cursor,
  1101.                               Option      : integer;
  1102.                           var StmntCnt,   
  1103.                               StmntExec   : integer;
  1104.                           var BufLen      : integer;
  1105.                           var StatBuf                ) : integer;
  1106.       begin
  1107.         SQLCode := DPMI_INTERFACE_FAIL;
  1108.  
  1109.         if XQLMLoaded then
  1110.           begin
  1111.             FillChar(pSpUtil^, SizeOf(tSpUtilStruc), #0);
  1112.  
  1113.             with pSpUtil^.XQLMStruc do
  1114.               begin
  1115.                 XQLMID    := XQLM_ID;
  1116.                 Fcn       := FCN_SPUTIL;
  1117.                 CursorID  := Cursor;
  1118.                 SessionID := SessID;
  1119.               end;
  1120.  
  1121.             with pSpUtil^.SpUtilRec do
  1122.               begin
  1123.                 UtilOption          := Option;
  1124.                 UtilStmntCnt        := StmntCnt;
  1125.                 UtilStmntExec       := StmntExec;
  1126.                 UtilBufLen          := BufLen;
  1127.  
  1128.                 UtilStatBuf.Offset  := 0; 
  1129.                 UtilStatBuf.Segment := XQLMBuffer[1].DPMIAddr.Segment; 
  1130.  
  1131.                 FillChar(XQLMBuffer[1].Buffer^, SQL_WORK_BUFFER_SIZE, #32);
  1132.                 Move(StatBuf, XQLMBuffer[1].Buffer^, BufLen);
  1133.               end;
  1134.  
  1135.             Regs    := DefaultRMR;
  1136.             Regs.DS := XQLMFuncs[FCN_SPUTIL].Segment;
  1137.     
  1138.             if SimRMI.SimRealModeInt(BTR_INT,@Regs) then
  1139.               SQLCode := pSpUtil^.XQLMStruc.Stat;
  1140.  
  1141.             if (SQLCode<=0) then
  1142.               begin
  1143.                 StmntCnt  := pSpUtil^.SpUtilRec.UtilStmntCnt;
  1144.                 StmntExec := pSpUtil^.SpUtilRec.UtilStmntExec;
  1145.                 BufLen    := pSpUtil^.SpUtilRec.UtilBufLen;
  1146.  
  1147.                 Move(XQLMBuffer[2].Buffer^,StatBuf,BufLen);
  1148.               end;
  1149.           end
  1150.         else
  1151.           SQLCode := XQLM_NOT_LOADED;
  1152.  
  1153.         XQLSpUtility := SQLCode;
  1154.       end;
  1155.  
  1156.  
  1157.  
  1158.  
  1159.     {************************************************************************}
  1160.     {***** internal: initing and allocating buffers in lower dos memory *****}
  1161.     {************************************************************************}
  1162.  
  1163.     function AllocDosXQLBuf(var DosAlloc  : tDosAlloc;
  1164.                             var BufferPtr : pXQLMArray) : boolean;
  1165.       begin
  1166.         AllocDosXQLBuf := FALSE;
  1167.         BufferPtr      := NIL;
  1168.  
  1169.         DosAlloc.Addresses := GlobalDosAlloc(SQL_WORK_BUFFER_SIZE);
  1170.         if (DosAlloc.Addresses=0) then 
  1171.           exit; 
  1172.  
  1173.         BufferPtr := Ptr(DosAlloc.Selector,0);
  1174.  
  1175.         FillChar(BufferPtr^, SQL_WORK_BUFFER_SIZE, #0);
  1176.  
  1177.         { No exit: everything works fine }
  1178.         AllocDosXQLBuf := TRUE;
  1179.       end;
  1180.  
  1181.     procedure DeallocDosXQLBuf(var BufferPtr : pXQLMArray; 
  1182.                                var DosAlloc  : tDosAlloc  );
  1183.       var res : integer;
  1184.       begin
  1185.         if (BufferPtr<>NIL) then
  1186.           begin
  1187.             res := GlobalDosFree(DosAlloc.Segment);
  1188.             BufferPtr := NIL;
  1189.             DosAlloc.Addresses := 0;
  1190.           end;
  1191.       end;
  1192.  
  1193.     function AllocDosStrBuf(var SegOfs    : tSegOfs;
  1194.                             var BufferPtr : pString  ) : boolean;
  1195.       var DosAlloc : tDosAlloc;
  1196.       begin
  1197.         AllocDosStrBuf := FALSE;
  1198.  
  1199.         SegOfs.Offset  := 0;    
  1200.         SegOfs.Segment := 0;    
  1201.         BufferPtr      := NIL;
  1202.  
  1203.         DosAlloc.Addresses := GlobalDosAlloc(SizeOf(string));
  1204.         if (DosAlloc.Addresses=0) then 
  1205.           exit; 
  1206.  
  1207.         BufferPtr      := Ptr(DosAlloc.Selector,0);
  1208.         SegOfs.Segment := DosAlloc.Segment;
  1209.  
  1210.         FillChar(BufferPtr^, SizeOf(string), #0);
  1211.  
  1212.         { No exit: everything works fine }
  1213.         AllocDosStrBuf := TRUE;
  1214.       end;
  1215.  
  1216.     procedure DeallocDosStrBuf(var BufferPtr : pString; SegOfs:tSegOfs);
  1217.       var res : integer;
  1218.       begin
  1219.         if (BufferPtr<>NIL) then
  1220.           begin
  1221.             res := GlobalDosFree(SegOfs.Segment);
  1222.             BufferPtr := NIL;
  1223.           end;
  1224.       end;
  1225.  
  1226.     function AllocDosIntBuf(var IntVar; 
  1227.                             var SegOfs    : tSegOfs;
  1228.                             var BufferPtr : pInteger ) : boolean;
  1229.       var DosAlloc : tDosAlloc;
  1230.       begin
  1231.         AllocDosIntBuf := FALSE;
  1232.  
  1233.         SegOfs.Offset  := 0;    
  1234.         SegOfs.Segment := 0;    
  1235.         BufferPtr      := NIL;
  1236.  
  1237.         DosAlloc.Addresses := GlobalDosAlloc(SizeOf(integer));
  1238.         if (DosAlloc.Addresses=0) then 
  1239.           exit; 
  1240.  
  1241.         BufferPtr      := Ptr(DosAlloc.Selector,0);
  1242.         SegOfs.Segment := DosAlloc.Segment;
  1243.  
  1244.         Move(IntVar, BufferPtr^, SizeOf(integer));
  1245.  
  1246.         { No exit: everything works fine }
  1247.         AllocDosIntBuf := TRUE;
  1248.       end;
  1249.  
  1250.     procedure DeallocDosIntBuf(var BufferPtr : pInteger; SegOfs:tSegOfs);
  1251.       var res : integer;
  1252.       begin
  1253.         if (BufferPtr<>NIL) then
  1254.           begin
  1255.             res := GlobalDosFree(SegOfs.Segment);
  1256.             BufferPtr := NIL;
  1257.           end;
  1258.       end;
  1259.  
  1260.  
  1261.     function BTRAvail : boolean;
  1262.       begin
  1263.         Regs := DefaultRMR;
  1264.         Regs.AX := $3500 + BTR_INT;
  1265.         if SimRMI.SimRealModeInt(DOS_INT,@Regs) then
  1266.           BTRAvail := (Regs.BX=BTR_OFFSET)
  1267.         else
  1268.           BTRAvail := FALSE;
  1269.       end;
  1270.  
  1271.  
  1272.     function XQLMAvail : boolean;
  1273.       begin
  1274.         SQLCode := XQLM_NOT_LOADED;
  1275.  
  1276.         with pBtrieve^.XQLMStruc do
  1277.           begin
  1278.             XQLMID    := XQLM_ID;
  1279.             Stat      := -1;
  1280.             Fcn       := FCN_INV;
  1281.             CursorId  := 0;
  1282.             SessionID := SessID;
  1283.           end;
  1284.  
  1285.         with pBtrieve^.BtrieveRec do
  1286.           BtrOp    := FCN_INV;
  1287.  
  1288.         Regs    := DefaultRMR;
  1289.         Regs.DS := XQLMFuncs[FCN_BTRIEVE].Segment;
  1290.  
  1291.         if SimRMI.SimRealModeInt(BTR_INT,@Regs) then
  1292.           if (pBtrieve^.XQLMStruc.Stat=FCN_RES_INV_XQLM) then
  1293.             SQLCode := 0;
  1294.  
  1295.         XQLMAvail := (SQLCode=0);
  1296.       end;
  1297.  
  1298.  
  1299.     function InitXQLMDPMI : integer;
  1300.       var i  : integer;
  1301.           ok : boolean;
  1302.       begin
  1303.         InitXQLMDPMI := BTRV_NOT_LOADED;
  1304.   
  1305.         for i := 1 to XQLMBUFFS do
  1306.           begin
  1307.             XQLMBuffer[i].DPMIAddr.Addresses := 0;
  1308.             XQLMBuffer[i].Buffer := NIL;
  1309.           end;
  1310.  
  1311.         for i := FCN_LOG_IN to FCN_BTRIEVE do
  1312.           XQLMFuncs[i].Addresses := 0;
  1313.   
  1314.  
  1315.         pXQLMStruc := NIL;
  1316.  
  1317.         pBtrieve   := NIL;
  1318.         pBtrStat   := NIL;
  1319.  
  1320.         pLogin     := NIL;
  1321.         pUserID    := NIL;
  1322.         pPswd      := NIL;
  1323.         pDataDic   := NIL;
  1324.         pDataPath  := NIL;
  1325.         pMachine   := NIL;
  1326.  
  1327.         pCompile   := NIL;
  1328.         pFormat    := NIL;
  1329.         pFetch     := NIL;
  1330.         pDescr     := NIL;
  1331.         pSubst     := NIL;
  1332.         pStatus    := NIL;
  1333.         pVersion   := NIL;
  1334.         pConvert   := NIL;
  1335.         pValidate  := NIL;
  1336.         pMask      := NIL;
  1337.         pSpUtil    := NIL;
  1338.  
  1339.  
  1340.         { work buffer's allocation }
  1341.         i  := 1;
  1342.         ok := TRUE;
  1343.         while (i<=XQLMBUFFS) and ok do
  1344.           begin
  1345.             ok := AllocDosXQLBuf(XQLMBuffer[i].DPMIAddr,XQLMBuffer[i].Buffer);
  1346.             inc(i);
  1347.           end;
  1348.   
  1349.         { btrieve func buffer allocation }
  1350.         if ok then
  1351.           begin
  1352.             XQLMFuncs[FCN_BTRIEVE].Addresses  := GlobalDosAlloc(SizeOf(tBtrieveStruc));
  1353.  
  1354.             if (XQLMFuncs[FCN_BTRIEVE].Addresses<>0) then 
  1355.               begin
  1356.                 pBtrieve := ptr(XQLMFuncs[FCN_BTRIEVE].Selector,0);
  1357.  
  1358.                 { btrieve func status buffer allocation }
  1359.                 ok := AllocDosIntBuf(BStat, pBtrieve^.BtrieveRec.BtrStat, pBtrStat);
  1360.               end
  1361.             else
  1362.               ok := FALSE;
  1363.           end;
  1364.  
  1365.         { login func buffer allocation }
  1366.         if ok then
  1367.           begin
  1368.             XQLMFuncs[FCN_LOG_IN].Addresses := GlobalDosAlloc(SizeOf(tLoginStruc));
  1369.  
  1370.             if (XQLMFuncs[FCN_LOG_IN].Addresses<>0) then 
  1371.               begin
  1372.                 pLogin := ptr(XQLMFuncs[FCN_LOG_IN].Selector,0);
  1373.  
  1374.                 { login func string buffer's allocation }
  1375.                 ok := AllocDosStrBuf(pLogin^.LoginRec.UserID,   pUserID  ) and
  1376.                       AllocDosStrBuf(pLogin^.LoginRec.Pswd,     pPswd    ) and
  1377.                       AllocDosStrBuf(pLogin^.LoginRec.DataDic,  pDataDic ) and
  1378.                       AllocDosStrBuf(pLogin^.LoginRec.DataPath, pDataPath) and
  1379.                       AllocDosStrBuf(pLogin^.LoginRec.Machine,  pMachine );
  1380.               end
  1381.             else
  1382.               ok := FALSE;
  1383.           end;
  1384.  
  1385.         { Logout func buffer allocation. Used also from the following func's:}
  1386.         {                                Cursor, Exec, Free,                 }
  1387.         if ok then
  1388.           begin
  1389.             XQLMFuncs[FCN_XQLM_STRUC].Addresses := GlobalDosAlloc(SizeOf(tXQLMStruc));
  1390.  
  1391.             if (XQLMFuncs[FCN_XQLM_STRUC].Addresses<>0) then 
  1392.               pXQLMStruc := ptr(XQLMFuncs[FCN_XQLM_STRUC].Selector,0)
  1393.             else
  1394.               ok := FALSE;
  1395.           end;
  1396.  
  1397.         { Compile func buffer allocation }
  1398.         if ok then
  1399.           begin
  1400.             XQLMFuncs[FCN_COMPILE].Addresses := GlobalDosAlloc(SizeOf(tCompileStruc));
  1401.  
  1402.             if (XQLMFuncs[FCN_COMPILE].Addresses<>0) then 
  1403.               pCompile := ptr(XQLMFuncs[FCN_COMPILE].Selector,0)
  1404.             else
  1405.               ok := FALSE;
  1406.           end;
  1407.  
  1408.         { Format func buffer allocation }
  1409.         if ok then
  1410.           begin
  1411.             XQLMFuncs[FCN_FORMAT].Addresses := GlobalDosAlloc(SizeOf(tFormatStruc));
  1412.  
  1413.             if (XQLMFuncs[FCN_FORMAT].Addresses<>0) then 
  1414.               pFormat := ptr(XQLMFuncs[FCN_FORMAT].Selector,0)
  1415.             else
  1416.               ok := FALSE;
  1417.           end;
  1418.  
  1419.         { Fetch func buffer allocation }
  1420.         if ok then
  1421.           begin
  1422.             XQLMFuncs[FCN_FETCH].Addresses := GlobalDosAlloc(SizeOf(tFetchStruc));
  1423.  
  1424.             if (XQLMFuncs[FCN_FETCH].Addresses<>0) then 
  1425.               pFetch := ptr(XQLMFuncs[FCN_FETCH].Selector,0)
  1426.             else
  1427.               ok := FALSE;
  1428.           end;
  1429.  
  1430.         { Describe func buffer allocation }
  1431.         if ok then
  1432.           begin
  1433.             XQLMFuncs[FCN_DESCRIBE].Addresses := GlobalDosAlloc(SizeOf(tDescrStruc));
  1434.  
  1435.             if (XQLMFuncs[FCN_DESCRIBE].Addresses<>0) then 
  1436.               pDescr := ptr(XQLMFuncs[FCN_DESCRIBE].Selector,0)
  1437.             else
  1438.               ok := FALSE;
  1439.           end;
  1440.  
  1441.         { Subst func buffer allocation }
  1442.         if ok then
  1443.           begin
  1444.             XQLMFuncs[FCN_SUBST].Addresses := GlobalDosAlloc(SizeOf(tSubstStruc));
  1445.  
  1446.             if (XQLMFuncs[FCN_SUBST].Addresses<>0) then 
  1447.               pSubst := ptr(XQLMFuncs[FCN_SUBST].Selector,0)
  1448.             else
  1449.               ok := FALSE;
  1450.           end;
  1451.  
  1452.         { Status func buffer allocation }
  1453.         if ok then
  1454.           begin
  1455.             XQLMFuncs[FCN_STAT].Addresses := GlobalDosAlloc(SizeOf(tStatusStruc));
  1456.  
  1457.             if (XQLMFuncs[FCN_STAT].Addresses<>0) then 
  1458.               pStatus := ptr(XQLMFuncs[FCN_STAT].Selector,0)
  1459.             else
  1460.               ok := FALSE;
  1461.           end;
  1462.  
  1463.         { Version func buffer allocation }
  1464.         if ok then
  1465.           begin
  1466.             XQLMFuncs[FCN_VERS].Addresses := GlobalDosAlloc(SizeOf(tVersionStruc));
  1467.  
  1468.             if (XQLMFuncs[FCN_VERS].Addresses<>0) then 
  1469.               pVersion := ptr(XQLMFuncs[FCN_VERS].Selector,0)
  1470.             else
  1471.               ok := FALSE;
  1472.           end;
  1473.  
  1474.         { Convert func buffer allocation }
  1475.         if ok then
  1476.           begin
  1477.             XQLMFuncs[FCN_CONV].Addresses := GlobalDosAlloc(SizeOf(tConvertStruc));
  1478.  
  1479.             if (XQLMFuncs[FCN_CONV].Addresses<>0) then 
  1480.               pConvert := ptr(XQLMFuncs[FCN_CONV].Selector,0)
  1481.             else
  1482.               ok := FALSE;
  1483.           end;
  1484.  
  1485.         { Validate func buffer allocation }
  1486.         if ok then
  1487.           begin
  1488.             XQLMFuncs[FCN_VAL].Addresses := GlobalDosAlloc(SizeOf(tValidateStruc));
  1489.  
  1490.             if (XQLMFuncs[FCN_VAL].Addresses<>0) then 
  1491.               pValidate := ptr(XQLMFuncs[FCN_VAL].Selector,0)
  1492.             else
  1493.               ok := FALSE;
  1494.           end;
  1495.  
  1496.         { Mask func buffer allocation }
  1497.         if ok then
  1498.           begin
  1499.             XQLMFuncs[FCN_MASK].Addresses := GlobalDosAlloc(SizeOf(tMaskStruc));
  1500.  
  1501.             if (XQLMFuncs[FCN_MASK].Addresses<>0) then 
  1502.               pMask := ptr(XQLMFuncs[FCN_MASK].Selector,0)
  1503.             else
  1504.               ok := FALSE;
  1505.           end;
  1506.  
  1507.         { SpUtil func buffer allocation }
  1508.         if ok then
  1509.           begin
  1510.             XQLMFuncs[FCN_SPUTIL].Addresses := GlobalDosAlloc(SizeOf(tSpUtilStruc));
  1511.  
  1512.             if (XQLMFuncs[FCN_SPUTIL].Addresses<>0) then 
  1513.               pSpUtil := ptr(XQLMFuncs[FCN_SPUTIL].Selector,0)
  1514.             else
  1515.               ok := FALSE;
  1516.           end;
  1517.  
  1518.         if ok then
  1519.           begin
  1520.             if BTRAvail then
  1521.               begin
  1522.                 if XQLMAvail then
  1523.                   XQLMLoaded := TRUE
  1524.                 else
  1525.                   begin
  1526.                     InitXQLMDPMI := XQLM_NOT_LOADED;
  1527.                     ok := FALSE;
  1528.                   end;
  1529.               end
  1530.             else
  1531.               ok := FALSE;
  1532.           end;
  1533.   
  1534.         if (not ok) then
  1535.           begin
  1536.             InitXQLMDPMI := DPMI_INTERFACE_FAIL;
  1537.             ExitXQLMDPMI;
  1538.             exit;
  1539.           end;
  1540.  
  1541.         InitXQLMDPMI := 0;
  1542.       end;
  1543.   
  1544.  
  1545.  
  1546.     procedure ExitXQLMDPMI;
  1547.       var i : integer;
  1548.       begin
  1549.         XQLMLoaded := FALSE;
  1550.  
  1551.         if (pSpUtil<>NIL) then
  1552.           begin
  1553.             i := GlobalDosFree(XQLMFuncs[FCN_SPUTIL].Segment);
  1554.             pSpUtil := NIL;
  1555.           end;
  1556.  
  1557.         if (pMask<>NIL) then
  1558.           begin
  1559.             i := GlobalDosFree(XQLMFuncs[FCN_MASK].Segment);
  1560.             pMask := NIL;
  1561.           end;
  1562.  
  1563.         if (pValidate<>NIL) then
  1564.           begin
  1565.             i := GlobalDosFree(XQLMFuncs[FCN_VAL].Segment);
  1566.             pValidate := NIL;
  1567.           end;
  1568.  
  1569.         if (pValidate<>NIL) then
  1570.           begin
  1571.             i := GlobalDosFree(XQLMFuncs[FCN_VAL].Segment);
  1572.             pValidate := NIL;
  1573.           end;
  1574.  
  1575.         if (pConvert<>NIL) then
  1576.           begin
  1577.             i := GlobalDosFree(XQLMFuncs[FCN_CONV].Segment);
  1578.             pConvert := NIL;
  1579.           end;
  1580.  
  1581.         if (pVersion<>NIL) then
  1582.           begin
  1583.             i := GlobalDosFree(XQLMFuncs[FCN_VERS].Segment);
  1584.             pVersion := NIL;
  1585.           end;
  1586.  
  1587.         if (pStatus<>NIL) then
  1588.           begin
  1589.             i := GlobalDosFree(XQLMFuncs[FCN_STAT].Segment);
  1590.             pStatus := NIL;
  1591.           end;
  1592.  
  1593.         if (pSubst<>NIL) then
  1594.           begin
  1595.             i := GlobalDosFree(XQLMFuncs[FCN_SUBST].Segment);
  1596.             pSubst := NIL;
  1597.           end;
  1598.  
  1599.         if (pDescr<>NIL) then
  1600.           begin
  1601.             i := GlobalDosFree(XQLMFuncs[FCN_DESCRIBE].Segment);
  1602.             pDescr := NIL;
  1603.           end;
  1604.  
  1605.         if (pFetch<>NIL) then
  1606.           begin
  1607.             i := GlobalDosFree(XQLMFuncs[FCN_FETCH].Segment);
  1608.             pFetch := NIL;
  1609.           end;
  1610.  
  1611.         if (pFormat<>NIL) then
  1612.           begin
  1613.             i := GlobalDosFree(XQLMFuncs[FCN_FORMAT].Segment);
  1614.             pFormat := NIL;
  1615.           end;
  1616.  
  1617.         if (pCompile<>NIL) then
  1618.           begin
  1619.             i := GlobalDosFree(XQLMFuncs[FCN_COMPILE].Segment);
  1620.             pCompile := NIL;
  1621.           end;
  1622.  
  1623.         if (pXQLMStruc<>NIL) then
  1624.           begin
  1625.             i := GlobalDosFree(XQLMFuncs[FCN_XQLM_STRUC].Segment);
  1626.             pXQLMStruc := NIL;
  1627.           end;
  1628.  
  1629.         if (pLogin<>NIL) then
  1630.           begin
  1631.             DeallocDosStrBuf(pMachine,  pLogin^.LoginRec.Machine);  
  1632.             DeallocDosStrBuf(pDataPath, pLogin^.LoginRec.DataPath);    
  1633.             DeallocDosStrBuf(pDataDic,  pLogin^.LoginRec.DataDic); 
  1634.             DeallocDosStrBuf(pPswd,     pLogin^.LoginRec.Pswd);
  1635.             DeallocDosStrBuf(pUserID,   pLogin^.LoginRec.UserID); 
  1636.  
  1637.             i := GlobalDosFree(XQLMFuncs[FCN_LOG_IN].Segment);
  1638.             pLogin := NIL;
  1639.           end;
  1640.  
  1641.         if (pBtrieve<>NIL) then
  1642.           begin
  1643.             DeallocDosIntBuf(pBtrStat, pBtrieve^.BtrieveRec.BtrStat);
  1644.             i := GlobalDosFree(XQLMFuncs[FCN_BTRIEVE].Segment);
  1645.             pBtrieve := NIL;
  1646.           end;
  1647.  
  1648.         for i := XQLMBUFFS downto 1 do
  1649.           DeallocDosXQLBuf(XQLMBuffer[i].Buffer,XQLMBuffer[i].DPMIAddr);
  1650.       end;
  1651.   
  1652. end.
  1653.